<?php
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
cfc('core')->checklogin();
$item=$this->plugin_setting('setting');
if($_RQ['op']=='main'){
	$params=array('uid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']);
	$pindex = max(1, intval($_RQ['page']));
	$psize = 15;
    $orderby='createtime desc';
	$total='';
	$history=pdo_getslice('jy_daijia_history',$params,array($pindex,$psize),$total,$fields,'',$orderby);	
	foreach($history as &$v){
		$v['lat_lng']=json_decode($v['lat_lng'],true);
	}
	$return['history']=$history;
	$return['post']=array('city'=>'');
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	$data=array_fields(array('start_seat','lat','end_lat','dest_seat','juli','time','gocity'),$postdata);
	if(!$postdata['mobile']){
		exi('请填写客户手机号','error');
	}
	$member = pdo_get('jy_daijia_member',array('mobile'=>$postdata['mobile'],'uniacid'=>$_SESSION['uniacid']),array('mid','mobile','name'));
	if(!$member['mid']){
		exi('未找到该手机号的客户，请协助客户扫码小程序二维码，注册完善信息！','error');
	}
	if(!$postdata['dest_seat']){
		exi('请选择目的地','error');
	}
	if(!$postdata['juli'] || !$postdata['price']){
		exi('未获取到距离和价格,请刷新重试','error');
	}
	$isorder=pdo_get('jy_daijia_order',array('uniacid'=>$_SESSION['uniacid'],'driver_id'=>$_SESSION['uid'],'status'=>array(0,1,6,7,8)));
	if($isorder['id']){
		exi('您还有未完成的订单，请先完成','error','jy_daijia/order/');
	}
	$data['lat']=ijson_encode($data['lat']);
	$data['end_lat']=ijson_encode($data['end_lat']);
	$data['mid']=$member['mid'];
	if($post['name']&&$post['mobile']){
		$data['name']=$post['name'];	
		$data['mobile']=$post['mobile'];	
	}else{
		$data['name']=$member['name'];	
		$data['mobile']=$member['mobile'];
	}
	$fees=$this->model('order')->get_fee($data['juli'],0,$post['gocity']);
	$data=array_merge($data,$fees);
	$orderid=$this->model('order')->create($data);
	$data['id']=$orderid;
	$this->model('worker')->getpai($data);
	$return['orderid']=$orderid;
	$return['msg']='';
	exi('已报单成功！','','/worker_order/');
}
?>